<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <link rel="stylesheet" href="../css/bootstrap.min.css">
    <script src="../../configure.js"></script>
</head>
<body style="background-color: #F5F6F7">
<div class="container" style="background-color:white;margin-top: 20px">
    <form id="form"  style="margin:10px 0px 10px">
        <span style="font-size:larger;color: black">添加站点</span>
        <hr style="border: black 1px solid">
        <!-- <div class="form-group">
            <label for="siteId">站点ID</label>
            <input type="text" class="form-control" name="siteId" id="siteId" placeholder="请输入站点ID">
        </div> -->
        <div class="form-group">
            <label for="siteName">站点名</label>
            <input type="text" class="form-control" name="siteName" id="siteName" placeholder="请输入站点名">
        </div>
        <div class="form-group">
            <label for="sitePhone">站点电话</label>
            <input type="text" class="form-control" name="sitePhone" id="sitePhone" placeholder="请输入站点电话">
        </div>
        <div data-toggle="distpicker" class="form-group">
            <label>地址 :</label>
            <select id="siteProvince" name="siteProvince"></select>
            <select id="siteCity" name="siteCity"></select>
            <select id="siteArea" name="siteArea"></select>
        </div>
        <button type="submit" class="btn btn-primary form-control ">添加</button>
    </form>
</div>
<script src="../js/jquery-3.3.1.min.js"></script>
<script src="../js/bootstrap.min.js"></script>
<script src="../js/distpicker.data.js"></script>
<script src="../js/distpicker.js"></script>
<script src="../layer/layer.js"></script>
<script type="text/javascript">
    $(function(){
        $("#form").submit(function(){
            let siteName = $("#siteName").val();
            let siteProvince = $("#siteProvince").val();
            let siteCity = $("#siteCity").val();
            let siteArea = $("#siteArea").val();
            let sitePhone = $("#sitePhone").val();
            let phoneReg = /(^1[3|4|5|7|8]\d{9}$)|(^09\d{8}$)/;
            if (sitePhone=="") {
                layer.msg("手机号码不能为空");
                return false
            }else{
                if (!phoneReg.test(sitePhone)) {
                    layer.msg("手机号格式不正确");
                    return false
                }
            }

            if (siteName=="") {
                layer.msg("站点名不能为空");
                return false
            }

            $.post(url+"/admin/addSite",{
                siteName:siteName,
                sitePhone:sitePhone,
                siteProvince:siteProvince,
                siteCity:siteCity,
                siteArea:siteArea
            },function(data){

                console.log(data)
                if(data.code == 0){
                    //录入成功
                    layer.msg("添加成功");
                    $("input").val("");
                    //$("input:eq(1)").val("顺丰速运");
                }else{
                    layer.msg("添加失败");
                    //录入失败
                }
            });
            return false
        });
    });
</script>
</body>
</html>